/// @tags: FFT
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>

namespace BlueQuantum {

typedef long long ll;

int const N = 1 << 18;

int n, m;
int cvt[N];
ll suma, sumb;

template <typename T>
inline T &read(T &x) {
  x = 0;
  bool f = false;
  short ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + (ch ^ '0'), ch = getchar();
  if (f) x = -x;
  return x;
}

struct Complex {
  double real, imag;
  Complex(double real = 0.0, double imag = 0.0) : real(real), imag(imag) {}
  inline Complex operator+(Complex const &rhs) const {
    return Complex(real + rhs.real, imag + rhs.imag);
  }
  inline Complex operator-(Complex const &rhs) const {
    return Complex(real - rhs.real, imag - rhs.imag);
  }
  inline Complex operator*(Complex const &rhs) const {
    return Complex(real * rhs.real - imag * rhs.imag, real * rhs.imag + imag * rhs.real);
  }
} f[N], g[N];

inline void FFT(Complex *f, bool const opt, int const maxl) {
  for (int i = 0; i < maxl; ++i)
    if (i < cvt[i]) std::swap(f[i], f[cvt[i]]);
  for (int i = 2; i <= maxl; i <<= 1) {
    int mid = i >> 1;
    Complex wn(cos(2.0 * M_PI / i), opt ? sin(2.0 * M_PI / i) : -sin(2.0 * M_PI / i));
    for (int j = 0; j < maxl; j += i) {
      Complex w(1, 0);
      for (int k = 0; k < mid; ++k, w = w * wn) {
        Complex tmp = f[j + k + mid] * w;
        f[j + k + mid] = f[j + k] - tmp;
        f[j + k] = f[j + k] + tmp;
      }
    }
  }
}

int main() {
  read(n), read(m);
  ll ans = 0;
  for (int i = 0, x; i < n; ++i) suma += f[n - i - 1].real = read(x), ans += 1ll * x * x;
  for (int i = 0, x; i < n; ++i) sumb += g[i].real = g[i + n].real = read(x), ans += 1ll * x * x;
  int maxl = 1, l = 0;
  while (maxl < n * 3) maxl <<= 1, ++l;
  for (int i = 0; i < maxl; ++i) cvt[i] = (cvt[i >> 1] >> 1 | ((i & 1) << (l - 1)));
  FFT(f, true, maxl), FFT(g, true, maxl);
  for (int i = 0; i < maxl; ++i) { f[i] = f[i] * g[i]; }
  FFT(f, false, maxl);
  ll max = 0;
  for (int i = n - 1; i < n << 1; ++i) max = std::max(max, static_cast<ll>(f[i].real / maxl + 0.5));
  ans -= 2 * max;
  ll mid = floor(1.0 * (sumb - suma) / n);
  ll tmp = mid * mid * n - 2 * mid * (sumb - suma);
  ++mid;
  ans += std::min(tmp, mid * mid * n - 2 * mid * (sumb - suma));
  printf("%lld", ans);
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("HNOI2017]礼物.in", "r", stdin);
  freopen("HNOI2017]礼物.out", "w", stdout);
#endif
#endif

  return BlueQuantum::main();
}